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

Commit4db485e

Browse files
committed
Put back a backwards-compatible version of sampling support functions.
Commit83e176e removed the longstandingsupport functions for block sampling without any consideration of theimpact this would have on third-party FDWs. The new API is not notablymore functional for FDWs than the old, so forcing them to change doesn'tseem like a good thing. We can provide the old API as a wrapper (moreor less) around the new one for a minimal amount of extra code.
1 parentf5916bb commit4db485e

File tree

3 files changed

+63
-4
lines changed

3 files changed

+63
-4
lines changed

‎src/backend/utils/misc/sampling.c

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* sampling.c
44
* Relation block sampling routines.
55
*
6-
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
6+
* Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
*
@@ -239,3 +239,47 @@ sampler_random_fract(SamplerRandomState randstate)
239239
{
240240
returnpg_erand48(randstate);
241241
}
242+
243+
244+
/*
245+
* Backwards-compatible API for block sampling
246+
*
247+
* This code is now deprecated, but since it's still in use by many FDWs,
248+
* we should keep it for awhile at least. The functionality is the same as
249+
* sampler_random_fract/reservoir_init_selection_state/reservoir_get_next_S,
250+
* except that a common random state is used across all callers.
251+
*/
252+
staticReservoirStateDataoldrs;
253+
254+
double
255+
anl_random_fract(void)
256+
{
257+
/* initialize if first time through */
258+
if (oldrs.randstate[0]==0)
259+
sampler_random_init_state(random(),oldrs.randstate);
260+
261+
/* and compute a random fraction */
262+
returnsampler_random_fract(oldrs.randstate);
263+
}
264+
265+
double
266+
anl_init_selection_state(intn)
267+
{
268+
/* initialize if first time through */
269+
if (oldrs.randstate[0]==0)
270+
sampler_random_init_state(random(),oldrs.randstate);
271+
272+
/* Initial value of W (for use when Algorithm Z is first applied) */
273+
returnexp(-log(sampler_random_fract(oldrs.randstate)) /n);
274+
}
275+
276+
double
277+
anl_get_next_S(doublet,intn,double*stateptr)
278+
{
279+
doubleresult;
280+
281+
oldrs.W=*stateptr;
282+
result=reservoir_get_next_S(&oldrs,t,n);
283+
*stateptr=oldrs.W;
284+
returnresult;
285+
}

‎src/include/commands/vacuum.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,9 @@ extern void analyze_rel(Oid relid, RangeVar *relation, int options,
198198
BufferAccessStrategybstrategy);
199199
externboolstd_typanalyze(VacAttrStats*stats);
200200

201+
/* in utils/misc/sampling.c --- duplicate of declarations in utils/sampling.h */
202+
externdoubleanl_random_fract(void);
203+
externdoubleanl_init_selection_state(intn);
204+
externdoubleanl_get_next_S(doublet,intn,double*stateptr);
205+
201206
#endif/* VACUUM_H */

‎src/include/utils/sampling.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* sampling.h
44
* definitions for sampling functions
55
*
6-
* Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
6+
* Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* src/include/utils/sampling.h
@@ -13,7 +13,8 @@
1313
#ifndefSAMPLING_H
1414
#defineSAMPLING_H
1515

16-
#include"storage/bufmgr.h"
16+
#include"storage/block.h"/* for typedef BlockNumber */
17+
1718

1819
/* Random generator for sampling code */
1920
typedefunsigned shortSamplerRandomState[3];
@@ -23,6 +24,7 @@ extern void sampler_random_init_state(long seed,
2324
externdoublesampler_random_fract(SamplerRandomStaterandstate);
2425

2526
/* Block sampling methods */
27+
2628
/* Data structure for Algorithm S from Knuth 3.4.2 */
2729
typedefstruct
2830
{
@@ -40,7 +42,8 @@ extern void BlockSampler_Init(BlockSampler bs, BlockNumber nblocks,
4042
externboolBlockSampler_HasMore(BlockSamplerbs);
4143
externBlockNumberBlockSampler_Next(BlockSamplerbs);
4244

43-
/* Reservoid sampling methods */
45+
/* Reservoir sampling methods */
46+
4447
typedefstruct
4548
{
4649
doubleW;
@@ -52,4 +55,11 @@ typedef ReservoirStateData *ReservoirState;
5255
externvoidreservoir_init_selection_state(ReservoirStaters,intn);
5356
externdoublereservoir_get_next_S(ReservoirStaters,doublet,intn);
5457

58+
/* Old API, still in use by assorted FDWs */
59+
/* For backwards compatibility, these declarations are duplicated in vacuum.h */
60+
61+
externdoubleanl_random_fract(void);
62+
externdoubleanl_init_selection_state(intn);
63+
externdoubleanl_get_next_S(doublet,intn,double*stateptr);
64+
5565
#endif/* SAMPLING_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp