On Thu, Apr 01, 2021 at 03:22:59PM +0200, Tomas Vondra wrote:
> On 4/1/21 3:09 PM, Zhihong Yu wrote:
> > Hi,
> > Can you try this patch ?
> >
> > Thanks
> >
> > diff --git a/src/backend/access/brin/brin_minmax_multi.c
> > b/src/backend/access/brin/brin_minmax_multi.c
> > index 70109960e8..25d6d2e274 100644
> > --- a/src/backend/access/brin/brin_minmax_multi.c
> > +++ b/src/backend/access/brin/brin_minmax_multi.c
> > @@ -2161,7 +2161,7 @@ brin_minmax_multi_distance_interval(PG_FUNCTION_ARGS)
> > delta = 24L * 3600L * delta;
> >
> > /* and add the time part */
> > - delta += result->time / (float8) 1000000.0;
> > + delta += (result->time + result->zone * USECS_PER_SEC) / (float8)
> > 1000000.0;
> >
>
> That won't work, because Interval does not have a "zone" field, so this
> won't even compile.
>
> The problem is that interval comparisons convert the value using 30 days
> per month (see interval_cmp_value), but the formula in this function
> uses 31. So either we can tweak that (seems to fix it for me), or maybe
> just switch to interval_cmp_value directly.
>
Changing to using month of 30 days on the formula fixed it.
and I found another issue, this time involves autovacuum which makes it
a little more complicated to reproduce.
Currently the only stable way to reproduce it is using pgbench:
pgbench -i postgres
psql -c "CREATE INDEX ON pgbench_history USING brin (tid
int4_minmax_multi_ops);" postgres
pgbench -c2 -j2 -T 300 -n postgres
Attached a backtrace
--
Jaime Casanova
Director de Servicios Profesionales
SystemGuards - Consultores de PostgreSQL
#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
set = {__val = {4194304, 140730649395040, 2, 6, 6603273,
94613689999344,
4611686018427388799, 139855637088934, 0, 281470681751456, 0, 0, 0,
0, 0, 0}}
pid = <optimized out>
tid = <optimized out>
ret = <optimized out>
#1 0x00007f32ad593535 in __GI_abort () at abort.c:79
save_stage = 1
act = {__sigaction_handler = {sa_handler = 0x0, sa_sigaction = 0x0},
sa_mask = {__val = {
0, 0, 0, 0, 0, 139855634845685, 2, 7147272211649118304,
7003431887686743910,
94613689999344, 7003770563910163344, 0, 17199369337215936768,
140730649395280, 0,
140730649396144}}, sa_flags = -144564240, sa_restorer = 0x0}
sigs = {__val = {32, 0 <repeats 15 times>}}
#2 0x0000560cf7cbc5d0 in ExceptionalCondition (conditionName=0x560cf7d370c9
"DatumGetBool(r)",
errorType=0x560cf7d36f74 "FailedAssertion", fileName=0x560cf7d36f60
"brin_minmax_multi.c",
lineNumber=455) at assert.c:69
No locals.
#3 0x0000560cf7628767 in AssertCheckExpandedRanges (bdesc=0x560cf9914e08,
colloid=0, attno=1,
attr=0x7f32a442d858, ranges=0x560cf991bbf0, nranges=10) at
brin_minmax_multi.c:455
r = 0
minval = 10
maxval = 10
i = 9
eq = 0x560cf9914ca0
lt = 0x560cf9914c40
#4 0x0000560cf762d17d in brin_minmax_multi_union (fcinfo=0x7ffe685dc520)
at brin_minmax_multi.c:2779
bdesc = 0x560cf9914e08
col_a = 0x560cf9923f88
col_b = 0x560cf9939898
colloid = 0
serialized_a = 0x560cf993d020
serialized_b = 0x560cf993d0b0
ranges_a = 0x560cf9923d48
ranges_b = 0x560cf9913be8
attno = 1
attr = 0x7f32a442d858
eranges = 0x560cf991bbf0
neranges = 10
cmpFn = 0x560cf9914c40
distanceFn = 0x560cf991aee0
distances = 0x560cf7d38d27
ctx = 0x560cf991bad0
oldctx = 0x560cf9923b00
#5 0x0000560cf7cc6ae2 in FunctionCall3Coll (flinfo=0x560cf991afb0,
collation=0,
arg1=94613726645768, arg2=94613726707592, arg3=94613726795928) at
fmgr.c:1188
fcinfodata = {fcinfo = {flinfo = 0x560cf991afb0, context = 0x0,
resultinfo = 0x0,
fncollation = 0, isnull = false, nargs = 3, args = 0x7ffe685dc540},
fcinfo_data = "\260\257\221\371\fV", '\000' <repeats 23 times>,
"\177\003\000\bN\221\371\fV\000\000\000;\222\371\fV\000\000\210?\222\371\fV\000\000\000\227\223\371\v\022\000\000\230\230\223\371\fV\000\000\000\257\221\371\fV\000"}
fcinfo = 0x7ffe685dc520
result = 17072012032
__func__ = "FunctionCall3Coll"
#6 0x0000560cf762541d in union_tuples (bdesc=0x560cf9914e08, a=0x560cf9923f60,
b=0x560cf993d078)
at brin.c:1618
unionFn = 0x560cf991afb0
col_a = 0x560cf9923f88
col_b = 0x560cf9939898
opcinfo = 0x560cf9914bf0
keyno = 0
db = 0x560cf9939870
cxt = 0x560cf9939750
oldcxt = 0x560cf9923b00
#7 0x0000560cf7624eb2 in summarize_range (indexInfo=0x560cf99243a8,
state=0x560cf9924e08,
heapRel=0x7f32a442dfb8, heapBlk=460, heapNumBlks=463) at brin.c:1427
newtup = 0x560cf9924110
newsize = 72
didupdate = false
samepage = true
phbuf = 2283
phtup = 0x560cf993d078
phsz = 32
offset = 17
scanNumBlks = 2
__func__ = "summarize_range"
#8 0x0000560cf762505b in brinsummarize (index=0x7f32a442e228,
heapRel=0x7f32a442dfb8,
pageRange=4294967295, include_partial=false, numSummarized=0x560cf9924600,
numExisting=0x560cf9924600) at brin.c:1509
tup = 0x0
off = 44
revmap = 0x560cf9913b30
state = 0x560cf9924e08
indexInfo = 0x560cf99243a8
heapNumBlocks = 463
pagesPerRange = 2
buf = 2526
startBlk = 460
#9 0x0000560cf762403d in brinvacuumcleanup (info=0x7ffe685dc840,
stats=0x560cf99245f8)
at brin.c:957
heapRel = 0x7f32a442dfb8
#10 0x0000560cf76c3eca in index_vacuum_cleanup (info=0x7ffe685dc840, stats=0x0)
at indexam.c:720
indexRelation = 0x7f32a442e228
__func__ = "index_vacuum_cleanup"
#11 0x0000560cf76bcb56 in lazy_cleanup_index (indrel=0x7f32a442e228,
stats=0x560cf9924ce0,
reltuples=72192, estimated_count=true, vacrelstats=0x560cf9924290) at
vacuumlazy.c:2566
ivinfo = {index = 0x7f32a442e228, analyze_only = false, report_progress
= false,
estimated_count = true, message_level = 13, num_heap_tuples = 72192,
strategy = 0x560cf98c6c88}
ru0 = {tv = {tv_sec = 1617513388, tv_usec = 224251}, ru = {ru_utime =
{tv_sec = 0,
tv_usec = 289410}, ru_stime = {tv_sec = 0, tv_usec = 23961},
{ru_maxrss = 41724,
__ru_maxrss_word = 41724}, {ru_ixrss = 0, __ru_ixrss_word = 0},
{ru_idrss = 0,
__ru_idrss_word = 0}, {ru_isrss = 0, __ru_isrss_word = 0},
{ru_minflt = 3762,
__ru_minflt_word = 3762}, {ru_majflt = 0, __ru_majflt_word = 0},
{ru_nswap = 0,
__ru_nswap_word = 0}, {ru_inblock = 0, __ru_inblock_word = 0},
{ru_oublock = 32,
__ru_oublock_word = 32}, {ru_msgsnd = 0, __ru_msgsnd_word = 0},
{ru_msgrcv = 0,
__ru_msgrcv_word = 0}, {ru_nsignals = 0, __ru_nsignals_word = 0},
{ru_nvcsw = 20,
__ru_nvcsw_word = 20}, {ru_nivcsw = 298, __ru_nivcsw_word = 298}}}
saved_err_info = {blkno = 4294967295, offnum = 0, phase =
VACUUM_ERRCB_PHASE_SCAN_HEAP}
__func__ = "lazy_cleanup_index"
#12 0x0000560cf76bc846 in lazy_cleanup_all_indexes (Irel=0x560cf9924650,
vacrelstats=0x560cf9924290, lps=0x0, nindexes=1) at vacuumlazy.c:2466
idx = 0
#13 0x0000560cf76baf73 in lazy_scan_heap (onerel=0x7f32a442dfb8,
params=0x560cf98c69d4,
vacrelstats=0x560cf9924290, Irel=0x560cf9924650, nindexes=1,
aggressive=false)
at vacuumlazy.c:1784
lps = 0x0
dead_tuples = 0x560cf99467e0
nblocks = 463
blkno = 463
tuple = {t_len = 48, t_self = {ip_blkid = {bi_hi = 0, bi_lo = 462},
ip_posid = 41},
t_tableOid = 162582, t_data = 0x7f32a5cb67d0}
relfrozenxid = 4557177
relminmxid = 4
empty_pages = 0
vacuumed_pages = 0
next_fsm_block_to_vacuum = 0
num_tuples = 24961
live_tuples = 24960
tups_vacuumed = 0
nkeep = 0
nunused = 0
i = 22028
ru0 = {tv = {tv_sec = 1617513388, tv_usec = 198387}, ru = {ru_utime =
{tv_sec = 0,
tv_usec = 269844}, ru_stime = {tv_sec = 0, tv_usec = 23961},
{ru_maxrss = 41724,
__ru_maxrss_word = 41724}, {ru_ixrss = 0, __ru_ixrss_word = 0},
{ru_idrss = 0,
__ru_idrss_word = 0}, {ru_isrss = 0, __ru_isrss_word = 0},
{ru_minflt = 3749,
__ru_minflt_word = 3749}, {ru_majflt = 0, __ru_majflt_word = 0},
{ru_nswap = 0,
__ru_nswap_word = 0}, {ru_inblock = 0, __ru_inblock_word = 0},
{ru_oublock = 32,
__ru_oublock_word = 32}, {ru_msgsnd = 0, __ru_msgsnd_word = 0},
{ru_msgrcv = 0,
__ru_msgrcv_word = 0}, {ru_nsignals = 0, __ru_nsignals_word = 0},
{ru_nvcsw = 17,
__ru_nvcsw_word = 17}, {ru_nivcsw = 273, __ru_nivcsw_word = 273}}}
vmbuffer = 0
next_unskippable_block = 463
skipping_blocks = false
frozen = 0x560cf9912ae0
buf = {data = 0x7ffe685dc94c "", len = -108204816, maxlen = 22028,
cursor = 1750976976}
initprog_index = {0, 1, 5}
initprog_val = {1, 463, 134733}
vistest = 0x560cf800a090 <GlobalVisDataRels>
__func__ = "lazy_scan_heap"
#14 0x0000560cf76b8e05 in heap_vacuum_rel (onerel=0x7f32a442dfb8,
params=0x560cf98c69d4,
bstrategy=0x560cf98c6c88) at vacuumlazy.c:547
vacrelstats = 0x560cf9924290
Irel = 0x560cf9924650
nindexes = 1
ru0 = {tv = {tv_sec = 0, tv_usec = 94613725920888}, ru = {ru_utime = {
tv_sec = 94566481283752, tv_usec = 94613725927416}, ru_stime = {
tv_sec = 140730649398240, tv_usec = 94613695145427}, {ru_maxrss =
0,
__ru_maxrss_word = 0}, {ru_ixrss = 94613725927416,
__ru_ixrss_word = 94613725927416}, {ru_idrss = 94613726047280,
__ru_idrss_word = 94613726047280}, {ru_isrss = 8481291744,
__ru_isrss_word = 8481291744}, {ru_minflt = 140730649398448,
__ru_minflt_word = 140730649398448}, {ru_majflt = 94613695139398,
__ru_majflt_word = 94613695139398}, {ru_nswap = 0,
__ru_nswap_word = 0}, {
ru_inblock = 94562155529729, __ru_inblock_word = 94562155529729},
{
ru_oublock = 18930846721, __ru_oublock_word = 18930846721}, {
ru_msgsnd = 140730649398528, __ru_msgsnd_word = 140730649398528},
{
ru_msgrcv = 698284372932888, __ru_msgrcv_word = 698284372932888},
{
ru_nsignals = 72057594037927936, __ru_nsignals_word =
72057594037927936}, {
ru_nvcsw = 698284372932888, __ru_nvcsw_word = 698284372932888}, {
ru_nivcsw = 72057594037927936, __ru_nivcsw_word =
72057594037927936}}}
starttime = 0
walusage_start = {wal_records = 13, wal_fpi = 0, wal_bytes = 2646}
walusage = {wal_records = 0, wal_fpi = 0, wal_bytes = 0}
secs = 8895207604540669953
usecs = 32766
read_rate = 6.9530179184725961e-310
write_rate = 0
aggressive = false
scanned_all_unfrozen = false
indnames = 0x0
xidFullScanLimit = 4149596875
mxactFullScanLimit = 4144967300
new_rel_pages = 22028
new_rel_allvisible = 4157395209
new_live_tuples = 4.6744320655811445e-310
new_frozen_xid = 32766
new_min_multi = 1750977552
errcallback = {previous = 0x0, callback = 0x560cf76bedce
<vacuum_error_callback>,
arg = 0x560cf9924290}
startreadtime = 0
startwritetime = 0
__func__ = "heap_vacuum_rel"
#15 0x0000560cf78beec9 in table_relation_vacuum (rel=0x7f32a442dfb8,
params=0x560cf98c69d4,
bstrategy=0x560cf98c6c88) at ../../../src/include/access/tableam.h:1678
No locals.
#16 0x0000560cf78c1b63 in vacuum_rel (relid=162582, relation=0x560cf9935850,
params=0x560cf98c69d4) at vacuum.c:1943
lmode = 4
onerel = 0x7f32a442dfb8
onerelid = {relId = 162582, dbId = 14616}
toast_relid = 0
save_userid = 10
save_sec_context = 0
save_nestlevel = 2
__func__ = "vacuum_rel"
#17 0x0000560cf78bfb94 in vacuum (relations=0x560cf9944908,
params=0x560cf98c69d4,
bstrategy=0x560cf98c6c88, isTopLevel=true) at vacuum.c:459
vrel = 0x560cf99358a8
cur__state = {l = 0x560cf9944908, i = 0}
cur = 0x560cf9944920
_save_exception_stack = 0x7ffe685dcf50
_save_context_stack = 0x0
_local_sigjmp_buf = {{__jmpbuf = {0, 4971879094006384564,
94613689999344,
140730649402256, 0, 0, 4971879094090270644, 1664808066973763508},
__mask_was_saved = 0, __saved_mask = {__val = {64, 56, 12884901920,
140730649398896,
94613697121185, 64, 94613726779184, 32, 17072084784,
94613726779592, 64,
94613726779184, 32, 94613726779184, 7784,
7164775530509643363}}}}
_do_rethrow = false
in_vacuum = true
stmttype = 0x560cf7e3528f "VACUUM"
in_outer_xact = false
use_own_xacts = true
__func__ = "vacuum"
#18 0x0000560cf7a4d2cb in autovacuum_do_vac_analyze (tab=0x560cf98c69d0,
bstrategy=0x560cf98c6c88) at autovacuum.c:3231
rangevar = 0x560cf9935850
rel = 0x560cf99358a8
rel_list = 0x560cf99358e0
#19 0x0000560cf7a4c01b in do_autovacuum () at autovacuum.c:2490
_save_exception_stack = 0x7ffe685dd2b0
_save_context_stack = 0x0
_local_sigjmp_buf = {{__jmpbuf = {0, 4971879093912012724,
94613689999344,
140730649402256, 0, 0, 4971879094012676020, 1664808227876833204},
__mask_was_saved = 0, __saved_mask = {__val = {94613726318544, 0,
16,
94613726323792, 5024, 94613697593005, 94613726318544, 18, 4592,
94613726323832,
94613697118376, 5024, 94613726318808, 140730649399408,
94613697119985,
140730649399440}}}}
_do_rethrow = false
tab = 0x560cf98c69d0
skipit = false
stdVacuumCostDelay = 0
stdVacuumCostLimit = 200
iter = {cur = 0x7f32ad0bb620, end = 0x7f32ad0bb620}
relid = 162582
classTup = 0x7f32a442dde0
isshared = false
cell__state = {l = 0x560cf98c6938, i = 2}
classRel = 0x7f32a440ea80
tuple = 0x0
relScan = 0x560cf98c6108
dbForm = 0x7f32a4419060
table_oids = 0x560cf98c6938
orphan_oids = 0x0
ctl = {num_partitions = 94613700409248, ssize = 8192, dsize =
94613726318544,
max_dsize = 94613726318768, keysize = 4, entrysize = 96, hash =
0x7ffe685dd110,
match = 0x0, keycopy = 0x7ffe685dd110, alloc = 0x0, hcxt =
0x7ffe685dd150,
hctl = 0x560cf7723853 <CommitTransaction+899>}
table_toast_map = 0x560cf9925c30
cell = 0x560cf98c6960
shared = 0x560cf990a570
dbentry = 0x560cf990a690
bstrategy = 0x560cf98c6c88
key = {sk_flags = 0, sk_attno = 17, sk_strategy = 3, sk_subtype = 0,
sk_collation = 950,
sk_func = {fn_addr = 0x560cf7b6b210 <chareq>, fn_oid = 61, fn_nargs =
2,
fn_strict = true, fn_retset = false, fn_stats = 2 '\002', fn_extra
= 0x0,
fn_mcxt = 0x560cf98c4fd0, fn_expr = 0x0}, sk_argument = 116}
pg_class_desc = 0x560cf98c50f0
effective_multixact_freeze_max_age = 400000000
did_vacuum = true
found_concurrent_worker = false
i = 22028
__func__ = "do_autovacuum"
#20 0x0000560cf7a4ad3d in AutoVacWorkerMain (argc=0, argv=0x0) at
autovacuum.c:1714
dbname = "postgres", '\000' <repeats 55 times>
local_sigjmp_buf = {{__jmpbuf = {0, 4971879093888944052,
94613689999344,
140730649402256, 0, 0, 4971879093909915572, 1664808228559062964},
__mask_was_saved = 1, __saved_mask = {__val =
{18446744066192964099, 0, 0, 0, 0, 0,
0, 0, 94613693360510, 0, 32976859536, 140730649400192,
94613694447999, 0,
2912088464, 140730649400192}}}}
dbid = 14616
__func__ = "AutoVacWorkerMain"
#21 0x0000560cf7a4a916 in StartAutoVacWorker () at autovacuum.c:1499
worker_pid = 0
__func__ = "StartAutoVacWorker"
#22 0x0000560cf7a63892 in StartAutovacuumWorker () at postmaster.c:5539
bn = 0x560cf986c040
__func__ = "StartAutovacuumWorker"
#23 0x0000560cf7a6330b in sigusr1_handler (postgres_signal_arg=10) at
postmaster.c:5243
save_errno = 4
__func__ = "sigusr1_handler"
#24 <signal handler called>
No locals.
#25 0x00007f32ad661ff7 in __GI___select (nfds=8, readfds=0x7ffe685dd850,
writefds=0x0,
exceptfds=0x0, timeout=0x7ffe685dd8d0) at
../sysdeps/unix/sysv/linux/select.c:41
resultvar = 18446744073709551612
sc_ret = <optimized out>
#26 0x0000560cf7a5eb50 in ServerLoop () at postmaster.c:1701
timeout = {tv_sec = 0, tv_usec = 704003}
rmask = {fds_bits = {224, 0 <repeats 15 times>}}
selres = -1
now = 1617513328
readmask = {fds_bits = {224, 0 <repeats 15 times>}}
nSockets = 8
last_lockfile_recheck_time = 1617513327
last_touch_time = 1617512427
__func__ = "ServerLoop"
#27 0x0000560cf7a5e4ef in PostmasterMain (argc=3, argv=0x560cf983ff00) at
postmaster.c:1409
opt = -1
status = 0
userDoption = 0x560cf98637f0 "data"
listen_addr_saved = true
i = 64
output_config_variable = 0x0
__func__ = "PostmasterMain"
#28 0x0000560cf7959d3c in main (argc=3, argv=0x560cf983ff00) at main.c:209
do_check_root = true