|
2 | 2 |
|
3 | 3 | # It's fairly hard to get parallel worker processes to block on locks,
|
4 | 4 | # since generally they don't want any locks their leader didn't already
|
5 |
| -# take. We cheat like mad here by making a function that takes a lock, |
6 |
| -# and is incorrectly marked parallel-safe so that it can execute in a worker. |
| 5 | +# take. We cheat like mad here by creating aliases for advisory-lock |
| 6 | +# functions that are incorrectly marked parallel-safe so that they can |
| 7 | +# execute in a worker. |
7 | 8 |
|
8 | 9 | # Note that we explicitly override any global settings of isolation level
|
9 | 10 | # or debug_parallel_query, to ensure we're testing what we intend to.
|
|
36 | 37 |
|
37 | 38 | setup
|
38 | 39 | {
|
| 40 | +-- The alias functions themselves. Really these return "void", but |
| 41 | +-- the implementation is such that we can declare them to return "int", |
| 42 | +-- and we will get a zero result. |
| 43 | + create function lock_share(bigint) returns int language internal as |
| 44 | + 'pg_advisory_xact_lock_shared_int8' strict parallel safe; |
| 45 | + |
| 46 | + create function lock_excl(bigint) returns int language internal as |
| 47 | + 'pg_advisory_xact_lock_int8' strict parallel safe; |
| 48 | + |
| 49 | +-- Inline-able wrappers that will produce an integer "1" result: |
39 | 50 | create function lock_share(int,int) returns int language sql as
|
40 |
| - 'select pg_advisory_xact_lock_shared($1); select 1;' parallel safe; |
| 51 | + 'select 1 - lock_share($1)' parallel safe; |
41 | 52 |
|
42 | 53 | create function lock_excl(int,int) returns int language sql as
|
43 |
| - 'select pg_advisory_xact_lock($1); select 1;' parallel safe; |
| 54 | + 'select 1 - lock_excl($1)' parallel safe; |
44 | 55 |
|
45 | 56 | create table bigt as select x from generate_series(1, 10000) x;
|
46 | 57 | analyze bigt;
|
|
0 commit comments