Re: assertion failure at cost_memoize_rescan() - Mailing list pgsql-hackers

From Kohei KaiGai
Subject Re: assertion failure at cost_memoize_rescan()
Date
Msg-id CAOP8fzaLocNELNs_50depJpMDVV-Rj6O+ESK2kMZgoWcB=Y_nA@mail.gmail.com
Whole thread Raw
In response to Re: assertion failure at cost_memoize_rescan()  (David Rowley <dgrowleyml@gmail.com>)
Responses Re: assertion failure at cost_memoize_rescan()
List pgsql-hackers
2024年6月17日(月) 8:27 David Rowley <dgrowleyml@gmail.com>:
>
> On Mon, 17 Jun 2024 at 10:23, Tomas Vondra
> <tomas.vondra@enterprisedb.com> wrote:
> > Interesting. Seems like a bug due to the two places clamping the values
> > inconsistently. It probably does not matter in other contexts because we
> > don't subtract the values like this, but here it triggers the assert.
> >
> > I guess the simplest fix would be to clamp "calls" the same way before
> > calculating hit_ratio. That makes the ">= 0" part of the assert somewhat
> > pointless, though.
>
> "calls" comes from the value passed as the final parameter in
> create_memoize_path().
>
> There's really only one call to that function and that's in get_memoize_path().
>
> return (Path *) create_memoize_path(root,
>                                             innerrel,
>                                             inner_path,
>                                             param_exprs,
>                                             hash_operators,
>                                             extra->inner_unique,
>                                             binary_mode,
>                                             outer_path->rows);
>
> It would be good to know what type of Path outer_path is.  Normally
> we'll clamp_row_est() on that field. I suspect we must have some Path
> type that isn't doing that.
>
> KaiGai-san,  what type of Path is outer_path?
>
It is CustomPath with rows = 3251872.916666667.
(I'm not certain whether the non-integer value in the estimated rows
is legal or not.)

According to the crash dump, try_partial_nestloop_path() takes this two paths,

(gdb) up
#7  0x0000000000860fc5 in try_partial_nestloop_path (root=0x133a968,
joinrel=0x15258d8, outer_path=0x1513c98, inner_path=0x15264c8,
pathkeys=0x0, jointype=JOIN_INNER, extra=0x7ffc494cddf0) at
joinpath.c:887
/home/kaigai/source/pgsql-16/src/backend/optimizer/path/joinpath.c:887:30713:beg:0x860fc5

(gdb) p *(CustomPath *)outer_path
$13 = {path = {type = T_CustomPath, pathtype = T_CustomScan, parent =
0x1513058, pathtarget = 0x1513268, param_info = 0x0, parallel_aware =
true, parallel_safe = true, parallel_workers = 2, rows =
3251872.916666667, startup_cost = 41886.752500000002,
    total_cost = 12348693.488611111, pathkeys = 0x0}, flags = 4,
custom_paths = 0x1514788, custom_private = 0x1514ee8, methods =
0x7f45211feca0 <gpujoin_path_methods>}

(gdb) p *(MemoizePath *)inner_path
$14 = {path = {type = T_MemoizePath, pathtype = T_Memoize, parent =
0x14dc800, pathtarget = 0x14dca10, param_info = 0x150d8a8,
parallel_aware = false, parallel_safe = true, parallel_workers = 0,
rows = 1, startup_cost = 0.44500000000000001,
    total_cost = 8.4284913207446568, pathkeys = 0x150d5c8}, subpath =
0x150d148, hash_operators = 0x1526428, param_exprs = 0x1526478,
singlerow = true, binary_mode = false, calls = 3251872.916666667,
est_entries = 3251873}

Best regards,
--
HeteroDB, Inc / The PG-Strom Project
KaiGai Kohei <kaigai@heterodb.com>



pgsql-hackers by date:

Previous
From: Chapman Flack
Date:
Subject: Re: jsonpath: Missing regex_like && starts with Errors?
Next
From: Bruce Momjian
Date:
Subject: Missing docs for new enable_group_by_reordering GUC