提交 7ea27fc5 编写于 作者: O Omer Arap

Import and modify analyze utility functions from 4.3

In the previous generation of analyze, gpdb provided features to merge
statistics such as MCVs (Most common values) and histograms for the root
or midlevel partitions from the leaf partition's statistics.

This commit imports the utility functions for merging MCVs and
histograms and modifies based on the needs of current version.
Signed-off-by: NBhunvesh Chaudhary <bchaudhary@pivotal.io>
上级 95279b10
......@@ -193,3 +193,50 @@ SiftDown(CdbHeap *hp, int iHole, void *newElement)
/* Fill the hole with the given element. */
CdbHeap_CopySlot(hp, curSlot, newElement);
} /* SiftDown */
/* Insert a copy of the given element into the heap. */
void
CdbHeap_Insert(CdbHeap *hp, void *newElement)
{
CdbHeapCmpFn comparator = hp->comparator;
void *comparatorContext = hp->comparatorContext;
int bytesPerSlot = hp->bytesPerSlot;
char *slot0 = CdbHeap_Slot(char, hp, 0);
char *slotN = CdbHeap_Slot(char, hp, hp->nSlotsUsed);
char *holeSlot;
Assert(newElement &&
hp->nSlotsUsed < hp->nSlotsMax);
/* Grow the heap by adding a rightmost leaf (initially a hole). */
holeSlot = slotN;
hp->nSlotsUsed++;
Assert(bytesPerSlot > 0);
/* Bubble the hole up to the proper level. Ancestors scoot down. */
while (slot0 < holeSlot)
{
/* Compute parent ptr.
(1) index(slot_k) = (addr(slot_k)-addr(slot_0)) / bytesPerSlot
(2) for Min-Heap, index(slot_dad) = floor((index(slot_child)-1)/2)
Combine the above two formula, we have
addr(slot_dad) = ((addr(slot_child) - addr(slot_0)) / bytesPerSlot - 1) / 2 * bytesPerSlot + addr(slot_0)
= addr(slot_0) + bytesPerSlot * ((addr(slot_child) - addr(slot_0) - bytesPerSlot) / bytesPerSlot / 2)
*/
char *dadSlot = slot0 + bytesPerSlot * (((holeSlot - slot0 - bytesPerSlot) / bytesPerSlot) >> 1);
/* Hole comes to rest where parent value <= new value. */
if ((*comparator)(dadSlot, newElement, comparatorContext) <= 0)
break;
/* Parent value sinks down; the hole bubbles up to the parent slot. */
CdbHeap_CopySlot(hp, holeSlot, dadSlot);
/* Ascend to parent. */
holeSlot = dadSlot;
}
/* Fill the hole with the new value. */
CdbHeap_CopySlot(hp, holeSlot, newElement);
} /* CdbHeap_Insert */
......@@ -15,7 +15,7 @@ override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS)
explain.o: explain_gp.c
OBJS = aggregatecmds.o alter.o analyze.o async.o cluster.o comment.o \
OBJS = aggregatecmds.o alter.o analyze.o analyzeutils.o async.o cluster.o comment.o \
collationcmds.o constraint.o conversioncmds.o copy.o \
dbcommands.o define.o discard.o explain.o extension.o \
foreigncmds.o functioncmds.o \
......
此差异已折叠。
......@@ -102,5 +102,8 @@ CdbHeap_DeleteMin(CdbHeap *hp);
void
CdbHeap_DeleteMinAndInsert(CdbHeap *hp, void* newElement);
/* Insert a copy of the given element into the heap. */
void
CdbHeap_Insert(CdbHeap *hp, void *newElement);
#endif /* CDBHEAP_H */
/*-------------------------------------------------------------------------
*
* analyzeutils.h
*
* Header file for utils functions in analyzeutils.c
*
* Copyright (c) 2015, Pivotal Inc.
*
*-------------------------------------------------------------------------
*/
#ifndef ANALYZEUTILS_H
#define ANALYZEUTILS_H
#include "commands/vacuum.h"
/* extern functions called by commands/analyze.c */
extern int aggregate_leaf_partition_MCVs(Oid relationOid,
AttrNumber attnum,
HeapTuple *heaptupleStats,
float4 *relTuples,
unsigned int nEntries,
void **result);
extern bool datumCompare(Datum d1, Datum d2, Oid opFuncOid);
extern float4 get_rel_reltuples(Oid relid);
extern int aggregate_leaf_partition_histograms(Oid relationOid,
AttrNumber attnum,
HeapTuple *heaptupleStats,
float4 *relTuples,
unsigned int nEntries,
void **result);
extern bool needs_sample(VacAttrStats **vacattrstats, int attr_cnt);
extern bool leaf_parts_analyzed(VacAttrStats *stats);
#endif /* ANALYZEUTILS_H */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册