Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 81f1a7a

Browse files
committed
Merge branch 'PGPROEE10_DEV' into PGPROEE10-pgpro-1078
2 parents 3872b94 + 2850075 commit 81f1a7a

File tree

865 files changed

+325921
-25880
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

865 files changed

+325921
-25880
lines changed

configure

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#! /bin/sh
22
# Guess values for system-dependent variables and create Makefiles.
3-
# Generated by GNU Autoconf 2.69 for PostgreSQL 10.0.
3+
# Generated by GNU Autoconf 2.69 for PostgreSQL 10.1.
44
#
55
# Report bugs to <bugs@postgrespro.ru>.
66
#
@@ -583,8 +583,8 @@ MAKEFLAGS=
583583
# Identity of this package.
584584
PACKAGE_NAME='PostgreSQL'
585585
PACKAGE_TARNAME='postgrespro'
586-
PACKAGE_VERSION='10.0'
587-
PACKAGE_STRING='PostgreSQL 10.0'
586+
PACKAGE_VERSION='10.1'
587+
PACKAGE_STRING='PostgreSQL 10.1'
588588
PACKAGE_BUGREPORT='bugs@postgrespro.ru'
589589
PACKAGE_URL=''
590590

@@ -1428,7 +1428,7 @@ if test "$ac_init_help" = "long"; then
14281428
# Omit some internal or obsolete options to make the list less imposing.
14291429
# This message is too long to be a string in the A/UX 3.1 sh.
14301430
cat <<_ACEOF
1431-
\`configure' configures PostgreSQL 10.0 to adapt to many kinds of systems.
1431+
\`configure' configures PostgreSQL 10.1 to adapt to many kinds of systems.
14321432
14331433
Usage: $0 [OPTION]... [VAR=VALUE]...
14341434
@@ -1494,7 +1494,7 @@ fi
14941494

14951495
if test -n "$ac_init_help"; then
14961496
case $ac_init_help in
1497-
short | recursive ) echo "Configuration of PostgreSQL 10.0:";;
1497+
short | recursive ) echo "Configuration of PostgreSQL 10.1:";;
14981498
esac
14991499
cat <<\_ACEOF
15001500
@@ -1655,7 +1655,7 @@ fi
16551655
test -n "$ac_init_help" && exit $ac_status
16561656
if $ac_init_version; then
16571657
cat <<\_ACEOF
1658-
PostgreSQL configure 10.0
1658+
PostgreSQL configure 10.1
16591659
generated by GNU Autoconf 2.69
16601660
16611661
Copyright (C) 2012 Free Software Foundation, Inc.
@@ -2367,7 +2367,7 @@ cat >config.log <<_ACEOF
23672367
This file contains any messages produced by compilers while
23682368
running configure, to aid debugging if configure makes a mistake.
23692369
2370-
It was created by PostgreSQL $as_me 10.0, which was
2370+
It was created by PostgreSQL $as_me 10.1, which was
23712371
generated by GNU Autoconf 2.69. Invocation command line was
23722372
23732373
$ $0 $@
@@ -16989,7 +16989,7 @@ _ACEOF
1698916989
# awk -F is a regex on some platforms, and not on others, so make "." a tab
1699016990
PG_VERSION_NUM="`echo "$PACKAGE_VERSION" | sed 's/[A-Za-z].*$//' |
1699116991
tr '.' ' ' |
16992-
$AWK '{printf "%d%02d%02d", $1, $2, (NF >= 3) ? $3 : 0}'`"
16992+
$AWK '{printf "%d%04d", $1, $2}'`"
1699316993

1699416994
cat >>confdefs.h <<_ACEOF
1699516995
#define PG_VERSION_NUM $PG_VERSION_NUM
@@ -17557,7 +17557,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
1755717557
# report actual input values of CONFIG_FILES etc. instead of their
1755817558
# values after options handling.
1755917559
ac_log="
17560-
This file was extended by PostgreSQL $as_me 10.0, which was
17560+
This file was extended by PostgreSQL $as_me 10.1, which was
1756117561
generated by GNU Autoconf 2.69. Invocation command line was
1756217562
1756317563
CONFIG_FILES = $CONFIG_FILES
@@ -17627,7 +17627,7 @@ _ACEOF
1762717627
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
1762817628
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
1762917629
ac_cs_version="\\
17630-
PostgreSQL config.status 10.0
17630+
PostgreSQL config.status 10.1
1763117631
configured by $0, generated by GNU Autoconf 2.69,
1763217632
with options \\"\$ac_cs_config\\"
1763317633

configure.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ dnl Read the Autoconf manual for details.
1717
dnl
1818
m4_pattern_forbid(^PGAC_)dnl to catch undefined macros
1919

20-
AC_INIT([PostgreSQL], [10.0], [bugs@postgrespro.ru], [postgrespro])
20+
AC_INIT([PostgreSQL], [10.1], [bugs@postgrespro.ru], [postgrespro])
2121
PACKAGE_TARNAME=postgrespro
2222

2323
m4_if(m4_defn([m4_PACKAGE_VERSION]), [2.69], [], [m4_fatal([Autoconf version 2.69 is required.
@@ -2232,7 +2232,7 @@ AC_DEFINE_UNQUOTED(PGPRO_VERSION_STR,
22322232
# awk -F is a regex on some platforms, and not on others, so make "." a tab
22332233
[PG_VERSION_NUM="`echo "$PACKAGE_VERSION" | sed 's/[A-Za-z].*$//' |
22342234
tr '.' ' ' |
2235-
$AWK '{printf "%d%02d%02d", $1, $2, (NF >= 3) ? $3 : 0}'`"]
2235+
$AWK '{printf "%d%04d", $1, $2}'`"]
22362236
AC_DEFINE_UNQUOTED(PG_VERSION_NUM, $PG_VERSION_NUM, [PostgreSQL version as a number])
22372237
AC_SUBST(PG_VERSION_NUM)
22382238

contrib/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ include $(top_builddir)/src/Makefile.global
77
SUBDIRS = \
88
adminpack \
99
amcheck \
10+
aqo \
1011
auth_delay \
1112
auto_explain \
1213
bloom \

contrib/aqo/Makefile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# contrib/aqo/Makefile
2+
3+
EXTENSION = aqo
4+
PGFILEDESC = "AQO - adaptive query optimization"
5+
MODULES = aqo
6+
DATA = aqo--1.0.sql
7+
OBJS = aqo.o auto_tuning.o cardinality_estimation.o cardinality_hooks.o \
8+
hash.o machine_learning.o path_utils.o postprocessing.o preprocessing.o \
9+
selectivity_cache.o storage.o utils.o $(WIN32RES)
10+
REGRESS = aqo_disabled aqo_controlled aqo_intelligent aqo_forced
11+
12+
MODULE_big = aqo
13+
ifdef USE_PGXS
14+
PG_CONFIG = pg_config
15+
PGXS := $(shell $(PG_CONFIG) --pgxs)
16+
include $(PGXS)
17+
else
18+
subdir = contrib/aqo
19+
top_builddir = ../..
20+
include $(top_builddir)/src/Makefile.global
21+
include $(top_srcdir)/contrib/contrib-global.mk
22+
endif

contrib/aqo/aqo--1.0.sql

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
2+
\echo Use "CREATE EXTENSION aqo" to load this file. \quit
3+
4+
CREATE TABLE aqo_queries (
5+
query_hash int PRIMARY KEY,
6+
learn_aqo boolean NOT NULL,
7+
use_aqo boolean NOT NULL,
8+
fspace_hash int NOT NULL,
9+
auto_tuning boolean NOT NULL
10+
);
11+
12+
CREATE TABLE aqo_query_texts (
13+
query_hash int PRIMARY KEY REFERENCES aqo_queries ON DELETE CASCADE,
14+
query_text varchar NOT NULL
15+
);
16+
17+
CREATE TABLE aqo_query_stat (
18+
query_hash int PRIMARY KEY REFERENCES aqo_queries ON DELETE CASCADE,
19+
execution_time_with_aqo double precision[],
20+
execution_time_without_aqo double precision[],
21+
planning_time_with_aqo double precision[],
22+
planning_time_without_aqo double precision[],
23+
cardinality_error_with_aqo double precision[],
24+
cardinality_error_without_aqo double precision[],
25+
executions_with_aqo bigint,
26+
executions_without_aqo bigint
27+
);
28+
29+
CREATE TABLE aqo_data (
30+
fspace_hash int NOT NULL REFERENCES aqo_queries ON DELETE CASCADE,
31+
fsspace_hash int NOT NULL,
32+
nfeatures int NOT NULL,
33+
features double precision[][],
34+
targets double precision[],
35+
UNIQUE (fspace_hash, fsspace_hash)
36+
);
37+
38+
CREATE INDEX aqo_queries_query_hash_idx ON aqo_queries (query_hash);
39+
CREATE INDEX aqo_query_texts_query_hash_idx ON aqo_query_texts (query_hash);
40+
CREATE INDEX aqo_query_stat_idx ON aqo_query_stat (query_hash);
41+
CREATE INDEX aqo_fss_access_idx ON aqo_data (fspace_hash, fsspace_hash);
42+
43+
ALTER TABLE aqo_data ALTER COLUMN features SET STORAGE MAIN;
44+
ALTER TABLE aqo_data ALTER COLUMN targets SET STORAGE MAIN;
45+
ALTER TABLE aqo_query_stat
46+
ALTER COLUMN execution_time_with_aqo SET STORAGE MAIN;
47+
ALTER TABLE aqo_query_stat
48+
ALTER COLUMN execution_time_without_aqo SET STORAGE MAIN;
49+
ALTER TABLE aqo_query_stat
50+
ALTER COLUMN planning_time_with_aqo SET STORAGE MAIN;
51+
ALTER TABLE aqo_query_stat
52+
ALTER COLUMN planning_time_without_aqo SET STORAGE MAIN;
53+
ALTER TABLE aqo_query_stat
54+
ALTER COLUMN cardinality_error_without_aqo SET STORAGE MAIN;
55+
ALTER TABLE aqo_query_stat
56+
ALTER COLUMN cardinality_error_with_aqo SET STORAGE MAIN;
57+
58+
INSERT INTO aqo_queries VALUES (0, false, false, 0, false);
59+
INSERT INTO aqo_query_texts VALUES (0, 'COMMON feature space (do not delete!)');
60+
-- a virtual query for COMMON feature space
61+
62+
CREATE FUNCTION invalidate_deactivated_queries_cache() RETURNS trigger
63+
AS 'MODULE_PATHNAME' LANGUAGE C;
64+
65+
CREATE TRIGGER aqo_queries_invalidate AFTER UPDATE OR DELETE OR TRUNCATE
66+
ON aqo_queries FOR EACH STATEMENT
67+
EXECUTE PROCEDURE invalidate_deactivated_queries_cache();

contrib/aqo/aqo.c

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
#include "aqo.h"
2+
3+
PG_MODULE_MAGIC;
4+
5+
void _PG_init(void);
6+
void _PG_fini(void);
7+
8+
/* Strategy of determining feature space for new queries. */
9+
int aqo_mode;
10+
11+
/* GUC variables */
12+
static const struct config_enum_entry format_options[] = {
13+
{"intelligent", AQO_MODE_INTELLIGENT, false},
14+
{"forced", AQO_MODE_FORCED, false},
15+
{"controlled", AQO_MODE_CONTROLLED, false},
16+
{"disabled", AQO_MODE_DISABLED, false},
17+
{NULL, 0, false}
18+
};
19+
20+
/* Parameters of autotuning */
21+
int aqo_stat_size = 20;
22+
int auto_tuning_window_size = 5;
23+
double auto_tuning_exploration = 0.1;
24+
int auto_tuning_max_iterations = 50;
25+
int auto_tuning_infinite_loop = 8;
26+
27+
/* stat_size > infinite_loop + window_size + 3 is required for auto_tuning*/
28+
29+
/* Machine learning parameters */
30+
double object_selection_prediction_threshold = 0.3;
31+
double object_selection_object_threshold = 0.1;
32+
double learning_rate = 1e-1;
33+
int aqo_k = 3;
34+
int aqo_K = 30;
35+
double log_selectivity_lower_bound = -30;
36+
37+
/* Parameters for current query */
38+
int query_hash;
39+
bool learn_aqo;
40+
bool use_aqo;
41+
int fspace_hash;
42+
bool auto_tuning;
43+
bool collect_stat;
44+
bool adding_query;
45+
bool explain_only;
46+
bool explain_aqo;
47+
48+
/* Query execution time */
49+
instr_time query_starttime;
50+
double query_planning_time;
51+
52+
/* Saved hook values in case of unload */
53+
post_parse_analyze_hook_type prev_post_parse_analyze_hook;
54+
planner_hook_type prev_planner_hook;
55+
ExecutorStart_hook_type prev_ExecutorStart_hook;
56+
ExecutorEnd_hook_type prev_ExecutorEnd_hook;
57+
set_baserel_rows_estimate_hook_type prev_set_baserel_rows_estimate_hook;
58+
get_parameterized_baserel_size_hook_type prev_get_parameterized_baserel_size_hook;
59+
set_joinrel_size_estimates_hook_type prev_set_joinrel_size_estimates_hook;
60+
get_parameterized_joinrel_size_hook_type prev_get_parameterized_joinrel_size_hook;
61+
copy_generic_path_info_hook_type prev_copy_generic_path_info_hook;
62+
ExplainOnePlan_hook_type prev_ExplainOnePlan_hook;
63+
64+
/*****************************************************************************
65+
*
66+
* CREATE/DROP EXTENSION FUNCTIONS
67+
*
68+
*****************************************************************************/
69+
70+
void
71+
_PG_init(void)
72+
{
73+
DefineCustomEnumVariable("aqo.mode",
74+
"Mode of aqo usage.",
75+
NULL,
76+
&aqo_mode,
77+
AQO_MODE_CONTROLLED,
78+
format_options,
79+
PGC_SUSET,
80+
0,
81+
NULL,
82+
NULL,
83+
NULL);
84+
85+
prev_planner_hook = planner_hook;
86+
planner_hook = &aqo_planner;
87+
prev_post_parse_analyze_hook = post_parse_analyze_hook;
88+
post_parse_analyze_hook = &get_query_text;
89+
prev_ExecutorStart_hook = ExecutorStart_hook;
90+
ExecutorStart_hook = &aqo_ExecutorStart;
91+
prev_ExecutorEnd_hook = ExecutorEnd_hook;
92+
ExecutorEnd_hook = &learn_query_stat;
93+
prev_set_baserel_rows_estimate_hook = set_baserel_rows_estimate_hook;
94+
set_baserel_rows_estimate_hook = &aqo_set_baserel_rows_estimate;
95+
prev_get_parameterized_baserel_size_hook =
96+
get_parameterized_baserel_size_hook;
97+
get_parameterized_baserel_size_hook =
98+
&aqo_get_parameterized_baserel_size;
99+
prev_set_joinrel_size_estimates_hook = set_joinrel_size_estimates_hook;
100+
set_joinrel_size_estimates_hook = &aqo_set_joinrel_size_estimates;
101+
prev_get_parameterized_joinrel_size_hook =
102+
get_parameterized_joinrel_size_hook;
103+
get_parameterized_joinrel_size_hook =
104+
&aqo_get_parameterized_joinrel_size;
105+
prev_copy_generic_path_info_hook = copy_generic_path_info_hook;
106+
copy_generic_path_info_hook = &aqo_copy_generic_path_info;
107+
prev_ExplainOnePlan_hook = ExplainOnePlan_hook;
108+
ExplainOnePlan_hook = print_into_explain;
109+
init_deactivated_queries_storage();
110+
}
111+
112+
void
113+
_PG_fini(void)
114+
{
115+
planner_hook = prev_planner_hook;
116+
post_parse_analyze_hook = prev_post_parse_analyze_hook;
117+
ExecutorStart_hook = prev_ExecutorStart_hook;
118+
ExecutorEnd_hook = prev_ExecutorEnd_hook;
119+
set_baserel_rows_estimate_hook = prev_set_baserel_rows_estimate_hook;
120+
get_parameterized_baserel_size_hook =
121+
prev_get_parameterized_baserel_size_hook;
122+
set_joinrel_size_estimates_hook = prev_set_joinrel_size_estimates_hook;
123+
get_parameterized_joinrel_size_hook =
124+
prev_get_parameterized_joinrel_size_hook;
125+
copy_generic_path_info_hook = prev_copy_generic_path_info_hook;
126+
ExplainOnePlan_hook = prev_ExplainOnePlan_hook;
127+
fini_deactivated_queries_storage();
128+
}
129+
130+
PG_FUNCTION_INFO_V1(invalidate_deactivated_queries_cache);
131+
132+
/*
133+
* Clears the cache of deactivated queries if the user changed aqo_queries
134+
* manually.
135+
*/
136+
Datum
137+
invalidate_deactivated_queries_cache(PG_FUNCTION_ARGS)
138+
{
139+
fini_deactivated_queries_storage();
140+
init_deactivated_queries_storage();
141+
PG_RETURN_POINTER(NULL);
142+
}

contrib/aqo/aqo.control

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# AQO extension
2+
comment = 'machine learning for cardinality estimation in optimizer'
3+
default_version = '1.0'
4+
module_pathname = '$libdir/aqo'
5+
relocatable = false

0 commit comments

Comments
 (0)