Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9914b75

Browse files
author
Vladimir Ershov
committed
Merge branch 'PGPROEE9_6' into PGPROEE9_6_scheduler
2 parentsbc2bd95 +631103e commit9914b75

23 files changed

+2834
-371
lines changed

‎.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
results/*
2+
regression.diffs
3+
regression.out
4+
*.o
5+
*.so
6+
*.gcda
7+
*.gcno
8+
*.gcov
9+
tags
10+
11+
aqo--?.?.sql

‎LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright (c) 2016-2018, Postgres Professional
2+
3+
Permission to use, copy, modify, and distribute this software and its documentation for any purpose, without fee, and without a written agreement is hereby granted, provided that the above copyright notice and this paragraph and the following two paragraphs appear in all copies.
4+
5+
IN NO EVENT SHALL POSTGRES PROFESSIONAL BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF POSTGRES PROFESSIONAL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6+
7+
POSTGRES PROFESSIONAL SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND POSTGRES PROFESSIONAL HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

‎Makefile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
# contrib/aqo/Makefile
22

33
EXTENSION = aqo
4+
EXTVERSION = 1.1
45
PGFILEDESC = "AQO - adaptive query optimization"
56
MODULES = aqo
6-
DATA = aqo--1.0.sql
77
OBJS = aqo.o auto_tuning.o cardinality_estimation.o cardinality_hooks.o\
88
hash.o machine_learning.o path_utils.o postprocessing.o preprocessing.o\
99
selectivity_cache.o storage.o utils.o$(WIN32RES)
10-
REGRESS = aqo_disabled aqo_controlled aqo_intelligent aqo_forced
10+
11+
REGRESS = aqo_disabled aqo_controlled aqo_intelligent aqo_forced aqo_learn
12+
EXTRA_REGRESS_OPTS=--temp-config=$(top_srcdir)/$(subdir)/conf.add
13+
14+
DATA = aqo--1.0.sql aqo--1.0--1.1.sql
15+
DATA_built = aqo--$(EXTVERSION).sql
1116

1217
MODULE_big = aqo
1318
ifdefUSE_PGXS
@@ -20,3 +25,7 @@ top_builddir = ../..
2025
include$(top_builddir)/src/Makefile.global
2126
include$(top_srcdir)/contrib/contrib-global.mk
2227
endif
28+
29+
30+
$(DATA_built):$(DATA)
31+
cat$+>$@

‎README.md

Lines changed: 290 additions & 70 deletions
Large diffs are not rendered by default.

‎aqo--1.0--1.1.sql

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
ALTERTABLE aqo_query_texts ALTER COLUMN query_text TYPEtext;
2+
3+
4+
DROPINDEX aqo_query_texts_query_hash_idx CASCADE;
5+
DROPINDEX aqo_queries_query_hash_idx CASCADE;
6+
DROPINDEX aqo_query_stat_idx CASCADE;
7+
DROPINDEX aqo_fss_access_idx CASCADE;
8+
9+
CREATEUNIQUE INDEXaqo_fss_access_idxON aqo_data (fspace_hash, fsspace_hash);
10+
11+
12+
CREATE OR REPLACEFUNCTIONaqo_migrate_to_1_1_get_pk(rel regclass) RETURNS regclassAS $$
13+
DECLARE
14+
idx regclass;
15+
BEGIN
16+
SELECTi.indexrelidFROMpg_catalog.pg_index iJOIN
17+
pg_catalog.pg_attribute aONa.attrelid=i.indrelidAND
18+
a.attnum= ANY(i.indkey)
19+
WHEREi.indrelid= relAND
20+
i.indisprimary
21+
INTO idx;
22+
23+
RETURN idx;
24+
END
25+
$$ LANGUAGE plpgsql;
26+
27+
28+
DO $$
29+
BEGIN
30+
EXECUTE format('ALTER TABLE %s RENAME to %s',
31+
aqo_migrate_to_1_1_get_pk('aqo_queries'),
32+
'aqo_queries_query_hash_idx');
33+
34+
EXECUTE format('ALTER TABLE %s RENAME to %s',
35+
aqo_migrate_to_1_1_get_pk('aqo_query_texts'),
36+
'aqo_query_texts_query_hash_idx');
37+
38+
EXECUTE format('ALTER TABLE %s RENAME to %s',
39+
aqo_migrate_to_1_1_get_pk('aqo_query_stat'),
40+
'aqo_query_stat_idx');
41+
END
42+
$$;
43+
44+
45+
DROPFUNCTION aqo_migrate_to_1_1_get_pk(regclass);

‎aqo.c

Lines changed: 35 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
PG_MODULE_MAGIC;
44

5-
void_PG_init(void);
6-
void_PG_fini(void);
5+
void_PG_init(void);
6+
77

88
/* Strategy of determining feature space for new queries. */
99
intaqo_mode;
@@ -13,6 +13,7 @@ static const struct config_enum_entry format_options[] = {
1313
{"intelligent",AQO_MODE_INTELLIGENT, false},
1414
{"forced",AQO_MODE_FORCED, false},
1515
{"controlled",AQO_MODE_CONTROLLED, false},
16+
{"learn",AQO_MODE_LEARN, false},
1617
{"disabled",AQO_MODE_DISABLED, false},
1718
{NULL,0, false}
1819
};
@@ -49,17 +50,17 @@ boolexplain_aqo;
4950
instr_timequery_starttime;
5051
doublequery_planning_time;
5152

52-
/* Saved hook valuesin case of unload*/
53-
post_parse_analyze_hook_typeprev_post_parse_analyze_hook;
54-
planner_hook_typeprev_planner_hook;
55-
ExecutorStart_hook_typeprev_ExecutorStart_hook;
56-
ExecutorEnd_hook_typeprev_ExecutorEnd_hook;
57-
set_baserel_rows_estimate_hook_typeprev_set_baserel_rows_estimate_hook;
58-
get_parameterized_baserel_size_hook_typeprev_get_parameterized_baserel_size_hook;
59-
set_joinrel_size_estimates_hook_typeprev_set_joinrel_size_estimates_hook;
60-
get_parameterized_joinrel_size_hook_typeprev_get_parameterized_joinrel_size_hook;
61-
copy_generic_path_info_hook_typeprev_copy_generic_path_info_hook;
62-
ExplainOnePlan_hook_typeprev_ExplainOnePlan_hook;
53+
/* Saved hook values */
54+
post_parse_analyze_hook_typeprev_post_parse_analyze_hook;
55+
planner_hook_typeprev_planner_hook;
56+
ExecutorStart_hook_typeprev_ExecutorStart_hook;
57+
ExecutorEnd_hook_typeprev_ExecutorEnd_hook;
58+
set_baserel_rows_estimate_hook_typeprev_set_baserel_rows_estimate_hook;
59+
get_parameterized_baserel_size_hook_typeprev_get_parameterized_baserel_size_hook;
60+
set_joinrel_size_estimates_hook_typeprev_set_joinrel_size_estimates_hook;
61+
get_parameterized_joinrel_size_hook_typeprev_get_parameterized_joinrel_size_hook;
62+
copy_generic_path_info_hook_typeprev_copy_generic_path_info_hook;
63+
ExplainOnePlan_hook_typeprev_ExplainOnePlan_hook;
6364

6465
/*****************************************************************************
6566
*
@@ -82,49 +83,28 @@ _PG_init(void)
8283
NULL,
8384
NULL);
8485

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-
}
86+
prev_planner_hook=planner_hook;
87+
planner_hook=aqo_planner;
88+
prev_post_parse_analyze_hook=post_parse_analyze_hook;
89+
post_parse_analyze_hook=get_query_text;
90+
prev_ExecutorStart_hook=ExecutorStart_hook;
91+
ExecutorStart_hook=aqo_ExecutorStart;
92+
prev_ExecutorEnd_hook=ExecutorEnd_hook;
93+
ExecutorEnd_hook=learn_query_stat;
94+
prev_set_baserel_rows_estimate_hook=set_baserel_rows_estimate_hook;
95+
set_baserel_rows_estimate_hook=aqo_set_baserel_rows_estimate;
96+
prev_get_parameterized_baserel_size_hook=get_parameterized_baserel_size_hook;
97+
get_parameterized_baserel_size_hook=aqo_get_parameterized_baserel_size;
98+
prev_set_joinrel_size_estimates_hook=set_joinrel_size_estimates_hook;
99+
set_joinrel_size_estimates_hook=aqo_set_joinrel_size_estimates;
100+
prev_get_parameterized_joinrel_size_hook=get_parameterized_joinrel_size_hook;
101+
get_parameterized_joinrel_size_hook=aqo_get_parameterized_joinrel_size;
102+
prev_copy_generic_path_info_hook=copy_generic_path_info_hook;
103+
copy_generic_path_info_hook=aqo_copy_generic_path_info;
104+
prev_ExplainOnePlan_hook=ExplainOnePlan_hook;
105+
ExplainOnePlan_hook=print_into_explain;
111106

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();
107+
init_deactivated_queries_storage();
128108
}
129109

130110
PG_FUNCTION_INFO_V1(invalidate_deactivated_queries_cache);

‎aqo.control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# AQO extension
22
comment = 'machine learning for cardinality estimation in optimizer'
3-
default_version = '1.0'
3+
default_version = '1.1'
44
module_pathname = '$libdir/aqo'
55
relocatable = false

‎aqo.h

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,20 @@
2626
* degradation respectively.
2727
* Feature spaces are described by their hashes (an integer value).
2828
*
29-
* This extension presentsthree default modes:
29+
* This extension presentsfour default modes:
3030
* "intelligent" mode tries to automatically tune AQO settings for the current
3131
* workload. It creates separate feature space for each new type of query
3232
* and then tries to improve the performance of such query type execution.
3333
* The automatic tuning may be manually deactivated for some queries.
34+
* "learn" mode creates separate feature space and enabled aqo learning and
35+
* usage for each new type of query. In general it is similar to "intelligent"
36+
* mode, but without auto_tuning setting enabled by default.
3437
* "forced" mode makes no difference between query types and use AQO for them
3538
* all in the similar way. It considers each new query type as linked to special
3639
* feature space called COMMON with hash 0.
37-
* "Controlled" mode ignores unknown query types. In this case AQO is completely
40+
* "controlled" mode ignores unknown query types. In this case AQO is completely
3841
* configured manually by user.
42+
* "disabled" mode ignores all queries.
3943
* Current mode is stored in aqo.mode variable.
4044
*
4145
* User can manually set up his own feature space configuration
@@ -108,7 +112,9 @@
108112
*/
109113
#ifndef__ML_CARD_H__
110114
#define__ML_CARD_H__
115+
111116
#include<math.h>
117+
112118
#include"postgres.h"
113119

114120
#include"fmgr.h"
@@ -142,15 +148,22 @@
142148
#include"utils/snapmgr.h"
143149

144150

151+
/* Check PostgreSQL version (9.6.0 contains important changes in planner) */
152+
#ifPG_VERSION_NUM<90600
153+
#error "Cannot build aqo with PostgreSQL version lower than 9.6.0"
154+
#endif
155+
145156
/* Strategy of determining feature space for new queries. */
146157
typedefenum
147158
{
148-
/* Creates new feature space for each query type */
159+
/* Creates new feature space for each query typewith auto-tuning enabled*/
149160
AQO_MODE_INTELLIGENT,
150161
/* Treats new query types as linked to the common feature space */
151162
AQO_MODE_FORCED,
152163
/* New query types are not linked with any feature space */
153164
AQO_MODE_CONTROLLED,
165+
/* Creates new feature space for each query type without auto-tuning */
166+
AQO_MODE_LEARN,
154167
/* Aqo is disabled for all queries */
155168
AQO_MODE_DISABLED,
156169
}AQO_MODE;
@@ -170,8 +183,8 @@ typedef struct
170183
intplanning_time_without_aqo_size;
171184
intcardinality_error_with_aqo_size;
172185
intcardinality_error_without_aqo_size;
173-
long longexecutions_with_aqo;
174-
long longexecutions_without_aqo;
186+
int64executions_with_aqo;
187+
int64executions_without_aqo;
175188
}QueryStat;
176189

177190
/* Parameters of autotuning */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp