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

Commit081c6a5

Browse files
Daniil Anisimovdanolivo
Daniil Anisimov
authored andcommitted
Removed the learn_cache routine.
Now it is not needed, because non-transactional storage is used.
1 parent4041b10 commit081c6a5

13 files changed

+50
-574
lines changed

‎Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ MODULE_big = aqo
77
OBJS =$(WIN32RES)\
88
aqo.o auto_tuning.o cardinality_estimation.o cardinality_hooks.o\
99
hash.o machine_learning.o path_utils.o postprocessing.o preprocessing.o\
10-
selectivity_cache.o storage.o utils.olearn_cache.oaqo_shared.o
10+
selectivity_cache.o storage.o utils.o aqo_shared.o
1111

1212
TAP_TESTS = 1
1313

‎aqo.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include"cardinality_hooks.h"
2323
#include"path_utils.h"
2424
#include"preprocessing.h"
25-
#include"learn_cache.h"
2625
#include"storage.h"
2726

2827

@@ -225,7 +224,7 @@ _PG_init(void)
225224
PGC_USERSET,
226225
0,
227226
NULL,
228-
lc_assign_hook,
227+
NULL,
229228
NULL
230229
);
231230

‎aqo.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ extern bool aqo_show_hash;
174174
externboolaqo_show_details;
175175
externintaqo_join_threshold;
176176
externbooluse_wide_search;
177+
externboolaqo_learn_statement_timeout;
177178

178179
/* Parameters for current query */
179180
typedefstructQueryContextData
@@ -256,10 +257,8 @@ int get_clause_hash(Expr *clause, int nargs, int *args_hash, int *eclass_hash);
256257

257258

258259
/* Storage interaction */
259-
externboolload_fss_ext(uint64fs,intfss,OkNNrdata*data,List**reloids,
260-
boolisSafe);
261-
externboolupdate_fss_ext(uint64fs,intfss,OkNNrdata*data,
262-
List*reloids,boolisTimedOut);
260+
externboolload_fss_ext(uint64fs,intfss,OkNNrdata*data,List**reloids);
261+
externboolupdate_fss_ext(uint64fs,intfss,OkNNrdata*data,List*reloids);
263262

264263
/* Query preprocessing hooks */
265264
externvoidprint_into_explain(PlannedStmt*plannedstmt,IntoClause*into,

‎aqo_shared.c

Lines changed: 0 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -12,161 +12,13 @@
1212
#include"storage.h"
1313

1414

15-
typedefstruct
16-
{
17-
intmagic;
18-
uint32total_size;
19-
uint32delta;
20-
}dsm_seg_hdr;
21-
22-
#definefree_space(hdr) (uint32) (temp_storage_size - sizeof(dsm_seg_hdr) - hdr->delta)
23-
#defineaddr(delta)((char *) dsm_segment_address(seg) + sizeof(dsm_seg_hdr) + delta)
24-
2515
shmem_startup_hook_typeprev_shmem_startup_hook=NULL;
2616
AQOSharedState*aqo_state=NULL;
27-
HTAB*fss_htab=NULL;
28-
staticintaqo_htab_max_items=1000;
2917
intfs_max_items=10000;/* Max number of different feature spaces in ML model */
3018
intfss_max_items=100000;/* Max number of different feature subspaces in ML model */
31-
staticuint32temp_storage_size=1024*1024*10;/* Storage size, in bytes */
32-
staticdsm_segment*seg=NULL;
33-
3419

35-
staticvoidaqo_detach_shmem(intcode,Datumarg);
3620
staticvoidon_shmem_shutdown(intcode,Datumarg);
3721

38-
39-
void*
40-
get_dsm_all(uint32*size)
41-
{
42-
dsm_seg_hdr*hdr;
43-
44-
Assert(LWLockHeldByMeInMode(&aqo_state->lock,LW_EXCLUSIVE));
45-
46-
if (aqo_state->dsm_handler==DSM_HANDLE_INVALID)
47-
{
48-
/* Fast path. No any cached data exists. */
49-
*size=0;
50-
returnNULL;
51-
}
52-
53-
if (!seg)
54-
{
55-
/* if segment exists we should connect to */
56-
seg=dsm_attach(aqo_state->dsm_handler);
57-
Assert(seg);
58-
dsm_pin_mapping(seg);
59-
before_shmem_exit(aqo_detach_shmem, (Datum)&aqo_state->dsm_handler);
60-
}
61-
62-
hdr= (dsm_seg_hdr*)dsm_segment_address(seg);
63-
*size=hdr->delta;
64-
return (char*)hdr+sizeof(dsm_seg_hdr);
65-
}
66-
67-
/*
68-
* Cleanup of DSM cache: set header into default state and zero the memory block.
69-
* This operation can be coupled with the cache dump, so we do it under an external
70-
* hold of the lock.
71-
*/
72-
void
73-
reset_dsm_cache(void)
74-
{
75-
dsm_seg_hdr*hdr;
76-
char*start;
77-
78-
Assert(LWLockHeldByMeInMode(&aqo_state->lock,LW_EXCLUSIVE));
79-
80-
if (aqo_state->dsm_handler==DSM_HANDLE_INVALID|| !seg)
81-
/* Fast path. No any cached data exists. */
82-
return;
83-
84-
hdr= (dsm_seg_hdr*)dsm_segment_address(seg);
85-
start= (char*)hdr+sizeof(dsm_seg_hdr);
86-
87-
/* Reset the cache */
88-
memset(start,0,hdr->delta);
89-
90-
hdr->delta=0;
91-
hdr->total_size=temp_storage_size-sizeof(dsm_seg_hdr);
92-
}
93-
94-
char*
95-
get_cache_address(void)
96-
{
97-
dsm_seg_hdr*hdr;
98-
99-
Assert(LWLockHeldByMeInMode(&aqo_state->lock,LW_EXCLUSIVE)||
100-
LWLockHeldByMeInMode(&aqo_state->lock,LW_SHARED));
101-
102-
if (aqo_state->dsm_handler!=DSM_HANDLE_INVALID)
103-
{
104-
if (!seg)
105-
{
106-
/* Another process created the segment yet. Just attach to. */
107-
seg=dsm_attach(aqo_state->dsm_handler);
108-
dsm_pin_mapping(seg);
109-
before_shmem_exit(aqo_detach_shmem, (Datum)&aqo_state->dsm_handler);
110-
}
111-
112-
hdr= (dsm_seg_hdr*)dsm_segment_address(seg);
113-
}
114-
else
115-
{
116-
/*
117-
* First request for DSM cache in this instance.
118-
* Create the DSM segment. Pin it to live up to instance shutdown.
119-
* Don't forget to detach DSM segment before an exit.
120-
*/
121-
seg=dsm_create(temp_storage_size,0);
122-
dsm_pin_mapping(seg);
123-
dsm_pin_segment(seg);
124-
aqo_state->dsm_handler=dsm_segment_handle(seg);
125-
before_shmem_exit(aqo_detach_shmem, (Datum)&aqo_state->dsm_handler);
126-
127-
hdr= (dsm_seg_hdr*)dsm_segment_address(seg);
128-
hdr->magic=AQO_SHARED_MAGIC;
129-
hdr->delta=0;
130-
hdr->total_size=temp_storage_size-sizeof(dsm_seg_hdr);
131-
}
132-
133-
Assert(seg);
134-
Assert(hdr->magic==AQO_SHARED_MAGIC&&hdr->total_size>0);
135-
136-
return (char*)hdr+sizeof(dsm_seg_hdr);
137-
}
138-
139-
uint32
140-
get_dsm_cache_pos(uint32size)
141-
{
142-
dsm_seg_hdr*hdr;
143-
uint32pos;
144-
145-
Assert(LWLockHeldByMeInMode(&aqo_state->lock,LW_EXCLUSIVE)||
146-
LWLockHeldByMeInMode(&aqo_state->lock,LW_SHARED));
147-
148-
(void)get_cache_address();
149-
hdr= (dsm_seg_hdr*)dsm_segment_address(seg);
150-
151-
if (free_space(hdr)<size||size==0)
152-
elog(ERROR,
153-
"DSM cache can't allcoate a mem block. Required: %u, free: %u",
154-
size,free_space(hdr));
155-
156-
pos=hdr->delta;
157-
hdr->delta+=size;
158-
Assert(free_space(hdr) >=0);
159-
returnpos;
160-
}
161-
162-
staticvoid
163-
aqo_detach_shmem(intcode,Datumarg)
164-
{
165-
if (seg!=NULL)
166-
dsm_detach(seg);
167-
seg=NULL;
168-
}
169-
17022
void
17123
aqo_init_shmem(void)
17224
{
@@ -177,7 +29,6 @@ aqo_init_shmem(void)
17729
prev_shmem_startup_hook();
17830

17931
aqo_state=NULL;
180-
fss_htab=NULL;
18132
stat_htab=NULL;
18233
qtexts_htab=NULL;
18334
data_htab=NULL;
@@ -189,7 +40,6 @@ aqo_init_shmem(void)
18940
{
19041
/* First time through ... */
19142

192-
aqo_state->dsm_handler=DSM_HANDLE_INVALID;
19343
aqo_state->qtexts_dsa_handler=DSM_HANDLE_INVALID;
19444
aqo_state->data_dsa_handler=DSM_HANDLE_INVALID;
19545

@@ -207,13 +57,6 @@ aqo_init_shmem(void)
20757
LWLockInitialize(&aqo_state->queries_lock,LWLockNewTrancheId());
20858
}
20959

210-
info.keysize=sizeof(htab_key);
211-
info.entrysize=sizeof(htab_entry);
212-
fss_htab=ShmemInitHash("AQO hash",
213-
aqo_htab_max_items,aqo_htab_max_items,
214-
&info,
215-
HASH_ELEM |HASH_BLOBS);
216-
21760
info.keysize=sizeof(((StatEntry*)0)->queryid);
21861
info.entrysize=sizeof(StatEntry);
21962
stat_htab=ShmemInitHash("AQO Stat HTAB",fs_max_items,fs_max_items,
@@ -279,7 +122,6 @@ aqo_memsize(void)
279122
Sizesize;
280123

281124
size=MAXALIGN(sizeof(AQOSharedState));
282-
size=add_size(size,hash_estimate_size(aqo_htab_max_items,sizeof(htab_entry)));
283125
size=add_size(size,hash_estimate_size(fs_max_items,sizeof(AQOSharedState)));
284126
size=add_size(size,hash_estimate_size(fs_max_items,sizeof(StatEntry)));
285127
size=add_size(size,hash_estimate_size(fs_max_items,sizeof(QueryTextEntry)));

‎aqo_shared.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,9 @@
99

1010
#defineAQO_SHARED_MAGIC0x053163
1111

12-
typedefstruct
13-
{
14-
/* XXX we assume this struct contains no padding bytes */
15-
uint64fs;
16-
int64fss;
17-
}htab_key;
18-
19-
typedefstruct
20-
{
21-
htab_keykey;
22-
uint32hdr_off;/* offset of data in DSM cache */
23-
}htab_entry;
24-
2512
typedefstructAQOSharedState
2613
{
2714
LWLocklock;/* mutual exclusion */
28-
dsm_handledsm_handler;
2915

3016
/* Storage fields */
3117
LWLockstat_lock;/* lock for access to stat storage */
@@ -47,16 +33,11 @@ typedef struct AQOSharedState
4733

4834
externshmem_startup_hook_typeprev_shmem_startup_hook;
4935
externAQOSharedState*aqo_state;
50-
externHTAB*fss_htab;
5136

5237
externintfs_max_items;/* Max number of feature spaces that AQO can operate */
5338
externintfss_max_items;
5439

5540
externSizeaqo_memsize(void);
56-
externvoidreset_dsm_cache(void);
57-
externvoid*get_dsm_all(uint32*size);
58-
externchar*get_cache_address(void);
59-
externuint32get_dsm_cache_pos(uint32size);
6041
externvoidaqo_init_shmem(void);
6142

6243
#endif/* AQO_SHARED_H */

‎cardinality_estimation.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ predict_for_relation(List *clauses, List *selectivities, List *relsigns,
8181
&ncols,&features);
8282
data=OkNNr_allocate(ncols);
8383

84-
if (load_fss_ext(query_context.fspace_hash,*fss,data,NULL, true))
84+
if (load_fss_ext(query_context.fspace_hash,*fss,data,NULL))
8585
result=OkNNr_predict(data,features);
8686
else
8787
{

‎cardinality_hooks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ predict_num_groups(PlannerInfo *root, Path *subpath, List *group_exprs,
452452
*fss=get_grouped_exprs_hash(child_fss,group_exprs);
453453
memset(&data,0,sizeof(OkNNrdata));
454454

455-
if (!load_fss_ext(query_context.fspace_hash,*fss,&data,NULL, true))
455+
if (!load_fss_ext(query_context.fspace_hash,*fss,&data,NULL))
456456
return-1;
457457

458458
Assert(data.rows==1);

‎expected/statement_timeout.out

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,29 @@ SELECT check_estimated_rows('SELECT *, pg_sleep(1) FROM t;');
111111
5
112112
(1 row)
113113

114+
-- Interrupted query should immediately appear in aqo_data
115+
SELECT 1 FROM aqo_reset();
116+
?column?
117+
----------
118+
1
119+
(1 row)
120+
121+
SET statement_timeout = 500;
122+
SELECT count(*) FROM aqo_data; -- Must be zero
123+
count
124+
-------
125+
0
126+
(1 row)
127+
128+
SELECT x, pg_sleep(0.1) FROM t WHERE x > 0;
129+
NOTICE: [AQO] Time limit for execution of the statement was expired. AQO tried to learn on partial data.
130+
ERROR: canceling statement due to statement timeout
131+
SELECT count(*) FROM aqo_data; -- Must be one
132+
count
133+
-------
134+
1
135+
(1 row)
136+
114137
SELECT 1 FROM aqo_reset();
115138
?column?
116139
----------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp