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

Commitae557bd

Browse files
committed
Add basic code for support of DSM cache.
1 parent303a9d9 commitae557bd

File tree

4 files changed

+92
-2
lines changed

4 files changed

+92
-2
lines changed

‎Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ PGFILEDESC = "AQO - Adaptive Query Optimization"
66
MODULE_big = aqo
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\
9-
selectivity_cache.o storage.o utils.o learn_cache.o$(WIN32RES)
9+
selectivity_cache.o storage.o utils.o learn_cache.oaqo_shared.o$(WIN32RES)
1010

1111
TAP_TESTS = 1
1212

‎aqo.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include"utils/selfuncs.h"
1919

2020
#include"aqo.h"
21+
#include"aqo_shared.h"
2122
#include"cardinality_hooks.h"
2223
#include"path_utils.h"
2324
#include"preprocessing.h"
@@ -125,7 +126,7 @@ _PG_init(void)
125126
{
126127
/*
127128
* In order to create our shared memory area, we have to be loaded via
128-
* shared_preload_libraries.If not, report an ERROR.
129+
* shared_preload_libraries. If not, report an ERROR.
129130
*/
130131
if (!process_shared_preload_libraries_in_progress)
131132
ereport(ERROR,
@@ -198,6 +199,8 @@ _PG_init(void)
198199
NULL
199200
);
200201

202+
prev_shmem_startup_hook=shmem_startup_hook;
203+
shmem_startup_hook=aqo_init_shmem;
201204
prev_planner_hook=planner_hook;
202205
planner_hook=aqo_planner;
203206
prev_ExecutorStart_hook=ExecutorStart_hook;
@@ -239,6 +242,10 @@ _PG_init(void)
239242
ALLOCSET_DEFAULT_SIZES);
240243
RegisterResourceReleaseCallback(aqo_free_callback,NULL);
241244
RegisterAQOPlanNodeMethods();
245+
246+
MarkGUCPrefixReserved("aqo");
247+
RequestAddinShmemSpace(MAXALIGN(sizeof(AQOSharedState)));
248+
242249
lc_init();
243250
}
244251

‎aqo_shared.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
*
3+
*/
4+
5+
#include"postgres.h"
6+
7+
#include"storage/shmem.h"
8+
9+
#include"aqo_shared.h"
10+
11+
shmem_startup_hook_typeprev_shmem_startup_hook=NULL;
12+
staticAQOSharedState*aqo_state=NULL;
13+
unsigned longtemp_storage_size=1024*1024;/* Storage size, in bytes */
14+
void*temp_storage=NULL;
15+
16+
staticvoid
17+
attach_dsm_segment(void)
18+
{
19+
dsm_segment*seg;
20+
21+
LWLockAcquire(&aqo_state->lock,LW_EXCLUSIVE);
22+
23+
if (aqo_state->dsm_handler!=DSM_HANDLE_INVALID)
24+
{
25+
seg=dsm_attach(aqo_state->dsm_handler);
26+
}
27+
else
28+
{
29+
seg=dsm_create(temp_storage_size,0);
30+
aqo_state->dsm_handler=dsm_segment_handle(seg);
31+
}
32+
33+
temp_storage=dsm_segment_address(seg);
34+
LWLockRelease(&aqo_state->lock);
35+
}
36+
37+
staticvoid
38+
aqo_detach_shmem(intcode,Datumarg)
39+
{
40+
dsm_handlehandler=*(dsm_handle*)arg;
41+
dsm_detach(dsm_find_mapping(handler));
42+
}
43+
44+
void
45+
aqo_init_shmem(void)
46+
{
47+
boolfound;
48+
49+
LWLockAcquire(AddinShmemInitLock,LW_EXCLUSIVE);
50+
aqo_state=ShmemInitStruct("aqo",sizeof(AQOSharedState),&found);
51+
if (!found)
52+
{
53+
/* First time through ... */
54+
LWLockInitialize(&aqo_state->lock,LWLockNewTrancheId());
55+
aqo_state->dsm_handler=DSM_HANDLE_INVALID;
56+
}
57+
LWLockRelease(AddinShmemInitLock);
58+
59+
LWLockRegisterTranche(aqo_state->lock.tranche,"aqo");
60+
on_shmem_exit(aqo_detach_shmem, (Datum)&aqo_state->dsm_handler);
61+
}

‎aqo_shared.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndefAQO_SHARED_H
2+
#defineAQO_SHARED_H
3+
4+
5+
#include"storage/dsm.h"
6+
#include"storage/ipc.h"
7+
#include"storage/lwlock.h"
8+
9+
10+
typedefstructAQOSharedState
11+
{
12+
LWLocklock;/* mutual exclusion */
13+
dsm_handledsm_handler;
14+
}AQOSharedState;
15+
16+
17+
externshmem_startup_hook_typeprev_shmem_startup_hook;
18+
19+
20+
externvoidaqo_init_shmem(void);
21+
22+
#endif/* AQO_SHARED_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp