mirror of
https://github.com/HypoPG/hypopg
synced 2026-05-24 09:38:21 +00:00
Move code for hypothetical index in dedicated files
This is still preliminary work for further support of hypothetical partitioning.
This commit is contained in:
parent
cac17141f5
commit
a04aebe5a1
7 changed files with 2112 additions and 2020 deletions
2
Makefile
2
Makefile
|
|
@ -7,7 +7,7 @@ REGRESS_OPTS = --inputdir=test
|
|||
PG_CONFIG ?= pg_config
|
||||
|
||||
MODULE_big = hypopg
|
||||
OBJS = hypopg.o hypopg_import.o
|
||||
OBJS = hypopg.o hypopg_import.o hypopg_index.o
|
||||
|
||||
all:
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
#include "utils/rel.h"
|
||||
#include "utils/syscache.h"
|
||||
|
||||
#include "hypopg_import.h"
|
||||
#include "include/hypopg_import.h"
|
||||
|
||||
|
||||
/* Copied from src/backend/optimizer/util/plancat.c, not exported.
|
||||
|
|
|
|||
1932
hypopg_index.c
Normal file
1932
hypopg_index.c
Normal file
File diff suppressed because it is too large
Load diff
29
include/hypopg.h
Normal file
29
include/hypopg.h
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* hypopg.h: Implementation of hypothetical indexes for PostgreSQL
|
||||
*
|
||||
* This program is open source, licensed under the PostgreSQL license.
|
||||
* For license terms, see the LICENSE file.
|
||||
*
|
||||
* Copyright (C) 2015-2018: Julien Rouhaud
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef _HYPOPG_H_
|
||||
#define _HYPOPG_H_
|
||||
|
||||
#include "catalog/catalog.h"
|
||||
#include "commands/explain.h"
|
||||
#include "nodes/nodeFuncs.h"
|
||||
#include "utils/memutils.h"
|
||||
|
||||
#include "include/hypopg_import.h"
|
||||
|
||||
extern bool isExplain;
|
||||
/* GUC for enabling / disabling hypopg during EXPLAIN */
|
||||
extern bool hypo_is_enabled;
|
||||
extern MemoryContext HypoMemoryContext;
|
||||
|
||||
Oid hypo_getNewOid(Oid relid);
|
||||
|
||||
#endif
|
||||
|
|
@ -9,6 +9,12 @@
|
|||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef _HYPOPG_IMPORT_H_
|
||||
#define _HYPOPG_IMPORT_H_
|
||||
|
||||
#include "nodes/pg_list.h"
|
||||
#include "optimizer/planner.h"
|
||||
#include "utils/rel.h"
|
||||
|
||||
|
||||
/* adapted from nbtinsert.h */
|
||||
|
|
@ -28,3 +34,5 @@ extern bool CheckMutability(Expr *expr);
|
|||
extern char *get_am_name(Oid amOid);
|
||||
#endif
|
||||
extern void get_opclass_name(Oid opclass, Oid actual_datatype, StringInfo buf);
|
||||
|
||||
#endif
|
||||
130
include/hypopg_index.h
Normal file
130
include/hypopg_index.h
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Copyright (C) 2015-2018: Julien Rouhaud
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef _HYPOPG_INDEX_H_
|
||||
#define _HYPOPG_INDEX_H_
|
||||
|
||||
#if PG_VERSION_NUM >= 90600
|
||||
#include "access/amapi.h"
|
||||
#endif
|
||||
#include "optimizer/plancat.h"
|
||||
#include "tcop/utility.h"
|
||||
|
||||
#define HYPO_INDEX_NB_COLS 12 /* # of column hypopg() returns */
|
||||
#define HYPO_INDEX_CREATE_COLS 2 /* # of column hypopg_create_index() returns */
|
||||
|
||||
#if PG_VERSION_NUM >= 90600
|
||||
/* hardcode some bloom values, bloom.h is not exported */
|
||||
#define sizeof_BloomPageOpaqueData 8
|
||||
#define sizeof_SignType 2
|
||||
#define BLOOMTUPLEHDRSZ 6
|
||||
#endif
|
||||
|
||||
|
||||
/*--- Structs --- */
|
||||
|
||||
/*--------------------------------------------------------
|
||||
* 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 */
|
||||
#if PG_VERSION_NUM >= 90300
|
||||
int tree_height; /* estimated index tree height, -1 if unknown */
|
||||
#endif
|
||||
|
||||
/* 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) */
|
||||
|
||||
#if PG_VERSION_NUM >= 90600
|
||||
amcostestimate_function amcostestimate;
|
||||
amcanreturn_function amcanreturn;
|
||||
#else
|
||||
RegProcedure amcostestimate; /* OID of the access method's cost fcn */
|
||||
RegProcedure amcanreturn; /* OID of the access method's canreturn fcn */
|
||||
#endif
|
||||
|
||||
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? */
|
||||
#if PG_VERSION_NUM >= 90500
|
||||
bool *canreturn; /* which index cols can be returned in an
|
||||
* index-only scan? */
|
||||
#else
|
||||
bool canreturn; /* can index return IndexTuples? */
|
||||
#endif
|
||||
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? */
|
||||
#if PG_VERSION_NUM >= 110000
|
||||
bool amcanparallel; /* does AM support parallel scan? */
|
||||
#endif
|
||||
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;
|
||||
|
||||
/* List of hypothetic indexes for current backend */
|
||||
extern List *hypoIndexes;
|
||||
|
||||
/*--- Functions --- */
|
||||
|
||||
void hypo_index_reset(void);
|
||||
|
||||
Datum hypopg(PG_FUNCTION_ARGS);
|
||||
Datum hypopg_create_index(PG_FUNCTION_ARGS);
|
||||
Datum hypopg_drop_index(PG_FUNCTION_ARGS);
|
||||
Datum hypopg_relation_size(PG_FUNCTION_ARGS);
|
||||
Datum hypopg_get_indexdef(PG_FUNCTION_ARGS);
|
||||
|
||||
extern explain_get_index_name_hook_type prev_explain_get_index_name_hook;
|
||||
const char *hypo_explain_get_index_name_hook(Oid indexId);
|
||||
|
||||
void hypo_injectHypotheticalIndex(PlannerInfo *root,
|
||||
Oid relationObjectId,
|
||||
bool inhparent,
|
||||
RelOptInfo *rel,
|
||||
Relation relation,
|
||||
hypoIndex *entry);
|
||||
|
||||
#endif
|
||||
Loading…
Reference in a new issue