Re: POC, WIP: OR-clause support for indexes - Mailing list pgsql-hackers

From jian he
Subject Re: POC, WIP: OR-clause support for indexes
Date
Msg-id CACJufxE_VHObCqw4VFK2zONCdYnAkY7w+mq+5jf82eWn5EF8Vw@mail.gmail.com
Whole thread Raw
In response to Re: POC, WIP: OR-clause support for indexes  (jian he <jian.universality@gmail.com>)
Responses Re: POC, WIP: OR-clause support for indexes
List pgsql-hackers
On Mon, Oct 7, 2024 at 10:06 PM jian he <jian.universality@gmail.com> wrote:
>
> assume v40 is the latest version.

make_bitmap_paths_for_or_group
{
    /*
     * First, try to match the whole group to the one index.
     */
    orargs = list_make1(ri);
    indlist = build_paths_for_OR(root, rel,
                                 orargs,
                                 other_clauses);
    if (indlist != NIL)
    {
        bitmapqual = choose_bitmap_and(root, rel, indlist);
        jointcost = bitmapqual->total_cost;
        jointlist = list_make1(bitmapqual);
    }
    /*
     * Also try to match all containing clauses 'one-by-one.
     */
    foreach(lc, args)
    {
        orargs = list_make1(lfirst(lc));
        indlist = build_paths_for_OR(root, rel,
                                     orargs,
                                     other_clauses);
        if (indlist == NIL)
        {
            splitlist = NIL;
            break;
        }
        bitmapqual = choose_bitmap_and(root, rel, indlist);
}

if other_clauses is not NIL, then "try to match all containing clauses
'one-by-one"
the foreach loop "foreach(lc, args)" will apply other_clauses in
build_paths_for_OR every time.
then splitcost will obviously be higher than jointcost.

if other_clauses is NIL.
"foreach(lc, args)" will have list_length(args) startup cost.
So overall, it looks like jointcost will alway less than splitcost,
the only corner case would be both are zero.

anyway, in make_bitmap_paths_for_or_group,
above line "Pick the best option."  I added:

    if (splitcost <= jointcost && splitcost != 0 && jointcost != 0)
        elog(INFO, "%s:%d splitcost <= jointcost and both is not
zero", __FILE_NAME__, __LINE__);
and the regress tests passed.
That means we don't need to iterate "((BoolExpr *)
ri->orclause)->args"  in make_bitmap_paths_for_or_group
?



pgsql-hackers by date:

Previous
From: Fujii Masao
Date:
Subject: Re: Function for listing pg_wal/summaries directory
Next
From: David Rowley
Date:
Subject: Re: Expand applicability of aggregate's sortop optimization